package com.maybach.common;

import com.maybach.common.enums.BaseConstants;
import com.maybach.common.enums.BaseConstants.ResultCode;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by well on 15/3/12.
 */
public class BizResult {

    private Map<String, Object> data = new HashMap<>();

    private String CODE = "code";
    private String MSG = "msg";
    private String RESULT = "result";

    public BizResult(){
        this.success();
    }

    public void success() {
        data.put(CODE, ResultCode.SUCCESS);
    }

    public boolean isSuccess(){
        return null != data.get(CODE) && data.get(CODE).equals(ResultCode.SUCCESS);
    }

    public void setResultMsg(String msg) {
        data.put(MSG, msg);
    }

    public void setResultCode(int resultCode) {
        data.put(CODE, resultCode);
    }

    public void setResultCodeAndMsg(int resultCode, String msg) {
        data.put(CODE, resultCode);
        data.put(MSG, msg);
    }

    public void setResultCodeAndMsg(int resultCode) {
        data.put(CODE, resultCode);
        data.put(MSG, BaseConstants.getMessage(resultCode));
    }

    public void setResultDate(Object resultData) {
        data.put(RESULT, resultData);
    }

    public Object getResultData() {
        return data.get(RESULT);
    }

    public void setKeyData(String key, Object value) {
        data.put(key, value);
    }

    public Map<String, Object> getData() {
        return data;
    }

    public int getResultCode() {
        return (int) data.get(CODE);
    }

    @Override
    public String toString(){
        return data.toString();
    }

}
